import booktxt from './booktxt';
import ixdzs from './ixdzs';
import xbiquge from './xbiquge';
import biquge9 from './biquge9';
import book230 from './book230';

export const apis = {
    'xsbiquge.com': xbiquge,
    'booktxt.com': booktxt,
    'ixdzs.com': ixdzs,
    'biquge9.cc': biquge9,
    'book230.com': book230,
};

let Context = {};

/**
 * 搜索小说
 * @param keyword
 * @param usedApi 使用的API id
 * @returns {*}
 */
Context.search = (keyword, usedApi) => {
    return getApi(usedApi).search(keyword);
};

/**
 * 获取章节列表
 * @param bookId
 * @param usedApi 使用的API id
 * @returns {*}
 */
Context.chapters = (bookId, usedApi) => {
    return getApi(usedApi).chapters(bookId);
};

/**
 * 获取章节内容
 * @param link
 * @param usedApi 使用的API id
 * @returns {*}
 */
Context.content = (link, usedApi) => {
    return getApi(usedApi).content(link);
};

const getApi = (apiId) => {
    let api = apis[apiId];
    if (!api) {
        throw new Error("未找到API");
    }
    return api;
};

export default Context;